package com.kbbywyclient.ui.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.TextView;

import com.kbbywyclient.R;
import com.kbbywyclient.data.entity.ScoreResult;
import com.kbbywyclient.ui.adapter.base.BaseLvAdapter;
import com.kbbywyclient.util.ViewUtils;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Description:
 * Created by FHW
 * on 2017/4/10
 */

public class ScoreAllAdapter extends BaseLvAdapter<ScoreResult> {
    static class ViewHolder {
        @BindView(R.id.tv_score_type)
        TextView tv_score_type;
        @BindView(R.id.tv_modify_score)
        TextView tv_modify_score;
        @BindView(R.id.tv_end_score)
        TextView tv_end_score;
        @BindView(R.id.tv_time)
        TextView tv_time;

        public ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }

    public ScoreAllAdapter(Context context, int itemLayout, List<ScoreResult> list) {
        super(context, itemLayout, list);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if(getItemViewType(position)==TYPE_NO_DATA){
            if(convertView==null){
                convertView=mInflater.inflate(R.layout.layout_data_error,null);
            }
        }else{
            ScoreResult scoreResult = getItem(position);
            ViewHolder holder ;
            if (convertView == null) {
                convertView = getItemView();
                holder = new ViewHolder(convertView);
                convertView.setTag(holder);
            } else {
                holder = (ViewHolder) convertView.getTag();
            }

            ViewUtils.setText(holder.tv_score_type, scoreResult.getScoreTypeName());
            ViewUtils.setText(holder.tv_modify_score, scoreResult.getModifyScore() + "");
            ViewUtils.setText(holder.tv_end_score, "余额：" + scoreResult.getEndScore());
            ViewUtils.setText(holder.tv_time, scoreResult.getAddDateTime());

            if (scoreResult.getModifyScore() > 0) {
                holder.tv_modify_score.setTextColor(getContext().getResources().getColor(R.color.color_FF5301));
            } else {
                holder.tv_modify_score.setTextColor(getContext().getResources().getColor(R.color.color_00BFFF));
            }
        }
        return convertView;
    }

    @Override
    public int getViewTypeCount() {
        return 2;
    }

    @Override
    public int getItemViewType(int position) {
        if(mList==null||mList.size()==0){
            return TYPE_NO_DATA;
        }
        return TYPE_NORMAL;
    }

    @Override
    public int getCount() {
        return mList==null||mList.size()==0?1:mList.size();
    }
}
